﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Diagnostics;
using System.IO;

namespace BYU_ECC {

    [TestFixture]
    class EncryptionExperiments {
        private Stopwatch watch = new Stopwatch();
        private string results;
		
        [TestFixtureSetUp]
        public void Init() {
            results = "";
        }

        [TestFixtureTearDown]
        public void End() {
            Console.WriteLine("\nResults:\n" + results);
        }

        [SetUp]
        public void Start() {

        }

        [TearDown]
        public void Stop() {
            watch.Stop();
			results += "," + watch.Elapsed.TotalSeconds + "\n";
			Console.WriteLine(","+ watch.Elapsed.TotalSeconds);
        }

		private string OpenFile(string fileName) {
			StreamReader inStream = new StreamReader("datafiles\\" + fileName);
			string message = inStream.ReadToEnd();
			watch.Reset();
			watch.Start();
			return message;
		}

		[TestCase(KeySizeEnum.Size140, "datafile1k")]
		[TestCase(KeySizeEnum.Size192, "datafile1k")]
        [TestCase(KeySizeEnum.Size224, "datafile1k")]
        [TestCase(KeySizeEnum.Size256, "datafile1k")]
		[TestCase(KeySizeEnum.Size384, "datafile1k")]
		[TestCase(KeySizeEnum.Size521, "datafile1k")]
		[TestCase(KeySizeEnum.Size1024, "datafile1k")]
		[TestCase(KeySizeEnum.Size2048, "datafile1k")]
		[TestCase(KeySizeEnum.Size3072, "datafile1k")]
        [TestCase(KeySizeEnum.Size7680, "datafile1k")]
        [TestCase(KeySizeEnum.Size15360, "datafile1k")]

		[TestCase(KeySizeEnum.Size140, "datafile10k")]
		[TestCase(KeySizeEnum.Size192, "datafile10k")]
        [TestCase(KeySizeEnum.Size224, "datafile10k")]
        [TestCase(KeySizeEnum.Size256, "datafile10k")]
		[TestCase(KeySizeEnum.Size384, "datafile10k")]
		[TestCase(KeySizeEnum.Size521, "datafile10k")]
        [TestCase(KeySizeEnum.Size1024, "datafile10k")]
        [TestCase(KeySizeEnum.Size2048, "datafile10k")]
        [TestCase(KeySizeEnum.Size3072, "datafile10k")]
        [TestCase(KeySizeEnum.Size7680, "datafile10k")]
        [TestCase(KeySizeEnum.Size15360, "datafile10k")]

		[TestCase(KeySizeEnum.Size140, "datafile100k")]
		[TestCase(KeySizeEnum.Size192, "datafile100k")]
        [TestCase(KeySizeEnum.Size224, "datafile100k")]
        [TestCase(KeySizeEnum.Size256, "datafile100k")]
		[TestCase(KeySizeEnum.Size384, "datafile100k")]
		[TestCase(KeySizeEnum.Size521, "datafile100k")]
        [TestCase(KeySizeEnum.Size1024, "datafile100k")]
        [TestCase(KeySizeEnum.Size2048, "datafile100k")]
        [TestCase(KeySizeEnum.Size3072, "datafile100k")]
        [TestCase(KeySizeEnum.Size7680, "datafile100k")]
        [TestCase(KeySizeEnum.Size15360, "datafile100k")]


		/*[TestCase(KeySizeEnum.Size140, "datafile10m")]
		[TestCase(KeySizeEnum.Size192, "datafile10m")]
        [TestCase(KeySizeEnum.Size224, "datafile10m")]
        [TestCase(KeySizeEnum.Size256, "datafile10m")]
		[TestCase(KeySizeEnum.Size384, "datafile10m")]
		[TestCase(KeySizeEnum.Size521, "datafile10m")]
        [TestCase(KeySizeEnum.Size1024, "datafile10m")]
        [TestCase(KeySizeEnum.Size2048, "datafile10m")]
        [TestCase(KeySizeEnum.Size3072, "datafile10m")]
        [TestCase(KeySizeEnum.Size7680, "datafile10m")]
        [TestCase(KeySizeEnum.Size15360, "datafile10m")]*/
		[Repeat(3)]
		public void TestRSAEncryption(KeySizeEnum keySize, string fileName) {
			string message = OpenFile(fileName);
			RSAAlgorithm.GenerateRSAAlgorithm(keySize);

			byte[] cipher = RSAAlgorithm.Instance().Encode(message);
			String decoded = RSAAlgorithm.Instance().Decode(cipher);
            Console.Write("RSA" + (int)keySize+","+fileName);
			results += fileName+",RSA" + (int)keySize;
        }

        [TestCase(KeySizeEnum.Size1024, "datafile1m")]
        /*[TestCase(KeySizeEnum.Size140, "datafile1m")]
        [TestCase(KeySizeEnum.Size192, "datafile1m")]
        [TestCase(KeySizeEnum.Size224, "datafile1m")]
        [TestCase(KeySizeEnum.Size256, "datafile1m")]
        [TestCase(KeySizeEnum.Size384, "datafile1m")]
        [TestCase(KeySizeEnum.Size521, "datafile1m")]
        [TestCase(KeySizeEnum.Size2048, "datafile1m")]
        [TestCase(KeySizeEnum.Size3072, "datafile1m")]
        [TestCase(KeySizeEnum.Size7680, "datafile1m")]
        [TestCase(KeySizeEnum.Size15360, "datafile1m")]*/
        public void TestRSAEncryption2(KeySizeEnum keySize, string fileName) {
            string message = OpenFile(fileName);
            RSAAlgorithm.GenerateRSAAlgorithm(keySize);

            byte[] cipher = RSAAlgorithm.Instance().Encode(message);
            String decoded = RSAAlgorithm.Instance().Decode(cipher);
            Console.Write("RSA" + (int)keySize + "," + fileName);
            results += fileName + ",RSA" + (int)keySize;
        }

        [TestCase(KeySizeEnum.Size192, "datafile1k")]
        [TestCase(KeySizeEnum.Size224, "datafile1k")]
        [TestCase(KeySizeEnum.Size256, "datafile1k")]
        [TestCase(KeySizeEnum.Size384, "datafile1k")]
        [TestCase(KeySizeEnum.Size521, "datafile1k")]

        [TestCase(KeySizeEnum.Size192, "datafile10k")]
        [TestCase(KeySizeEnum.Size224, "datafile10k")]
        [TestCase(KeySizeEnum.Size256, "datafile10k")]
        [TestCase(KeySizeEnum.Size384, "datafile10k")]
        [TestCase(KeySizeEnum.Size521, "datafile10k")]
        
        [TestCase(KeySizeEnum.Size192, "datafile100k")]
        [TestCase(KeySizeEnum.Size224, "datafile100k")]
        [TestCase(KeySizeEnum.Size256, "datafile100k")]
        [TestCase(KeySizeEnum.Size384, "datafile100k")]
        [TestCase(KeySizeEnum.Size521, "datafile100k")]
        
        
        /*[TestCase(KeySizeEnum.Size192, "datafile10m")]
        [TestCase(KeySizeEnum.Size224, "datafile10m")]
        [TestCase(KeySizeEnum.Size256, "datafile10m")]
        [TestCase(KeySizeEnum.Size384, "datafile10m")]
        [TestCase(KeySizeEnum.Size521, "datafile10m")]*/
        [Repeat(3)]
        public void TestECCEncryption(KeySizeEnum keySize, string fileName) {
			string message = OpenFile(fileName);

            Console.Write("ECC" + (int)keySize + "," + fileName);
            results += fileName + ",ECC" + (int)keySize;
            ParameterGenerator.GenerateTestParameters(keySize);
            KeyPairs.GenerateKeyPairs();
			Encoder.GenerateEncoder(message);
			Decoder.GenerateDecoder();
        }


        [TestCase(KeySizeEnum.Size192, "datafile1m")]
        /*[TestCase(KeySizeEnum.Size224, "datafile1m")]
        [TestCase(KeySizeEnum.Size256, "datafile1m")]
        [TestCase(KeySizeEnum.Size384, "datafile1m")]
        [TestCase(KeySizeEnum.Size521, "datafile1m")]*/
        public void TestECCEncryption2(KeySizeEnum keySize, string fileName) {
            string message = OpenFile(fileName);

            Console.Write("ECC" + (int)keySize + "," + fileName);
            results += fileName + ",ECC" + (int)keySize;
            ParameterGenerator.GenerateTestParameters(keySize);
            KeyPairs.GenerateKeyPairs();
            Encoder.GenerateEncoder(message);
            Decoder.GenerateDecoder();
        }

    }
}
